<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="box"></div>
    <script>
        const oBox = document.querySelector('#box');

        // 创建监听实例
        const observer = new MutationObserver(mutations => {
            console.log(mutations);
        });
        // 指定监听 DOM 和相关配置
        observer.observe(oBox, {
            attributes: true
        });
        // 测试
        oBox.setAttribute('uname', 'ifer');
        oBox.style.backgroundColor = 'red';
    </script>
</body>

</html>